Std::cin >> *aa results in a bus error?

The setCharString with the char *s signature is dereferencing the first element of an array of pointers to char It has not been allocated. If you change the declaration of aa to char aa1000 it will probably run There are some other issues too (also pointed out by others). The assignment to the variable stringValue is also dereferencing memory that does not appear to have been allocated.It's hard to say what the usage is, but it should maybe not have the declaration.

In addition, the assignment is storing a pointer to stack memory, which will likely not be valid after another function call.

The setCharString with the char *s signature is dereferencing the first element of an array of pointers to char*. It has not been allocated. If you change the declaration of aa to char aa1000;, it will probably run.

There are some other issues too (also pointed out by others). The assignment to the variable stringValue is also dereferencing memory that does not appear to have been allocated. It's hard to say what the usage is, but it should maybe not have the declaration.In addition, the assignment is storing a pointer to stack memory, which will likely not be valid after another function call.

Awesome! Thanks! – WTP Apr 25 '10 at 13:29 1 ...until someone enters 1005 characters.

– Alex Apr 25 '10 at 13:30 @Alex: I changed it to char aa, std::cin >> &aa and myString. SetCharString(&aa) and removed the asterisks from the function declecations. It works now without a limit of characters.

– WTP Apr 25 '10 at 13:44.

When you say: char *aa1000; std::cin >> *aa; *aa has no memory allocated to it. Same sort of problem here: char *stringValue; And the name __CPP_PPString is reserved in C++, as are all names that contain a double underscore or begin with an underscore and an uppercase letter. You are not allowed to create them in your own code.

Char *aa1000; is not what you think it is. It's an array of 1000 char *'s. Use std::string instead.

That way, you don't have to worry about someone entering more than 1000 characters and exploiting your program. E.g. Std::string input; std::cin >> input.

The problem of this, is that soon I'll not link to the standard library anymore. The classes are actually in my own static library. Maybe I could use std::string as buffer for now.

Thanks anyway. – WTP Apr 25 '10 at 13:28 @Koning you are rewriting standard lib? – Kugel Apr 25 '10 at 13:46 @Kugel, not really.

I'm writing a program which links to my static-library to test it. That static-library indeed doesn't link to anything. – WTP Apr 25 '10 at 13:50.

Try using a different compiler or enabling all warnings for the one you're using, the compiler should be telling you the errors for this code, you don't need to find out at runtime. For example, Comeau online will tell you: "ComeauTest. C", line 4: error: incomplete type is not allowed char *stringValue; ^ "ComeauTest.

C", line 23: warning: variable "aa" is used before its value is set std::cin >> *aa.

I'm using GCC. Switching to another one is a real pain with Xcode... – WTP Apr 25 '10 at 13:37.

If I read or write one of those addresses, I get a bus error. You can also get a bus error if there's actually a hardware problem on the bus. If you're running on a platform with virtual memory, you might not be able to intentionally generate a bus error with your program unless it's a device driver or other kernel mode software.

An invalid memory access would likely be trapped as an access violation or similar by the memory manager (and it never even has a chance to hit the bus).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions